//
//  ViewController.swift
//  Client
//
//  Created by 叶情宇 on 2017/7/4.
//  Copyright © 2017年 叶情宇. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    fileprivate lazy var socket:SocketManager = SocketManager(address: "127.0.0.1", port: 7888)

    override func viewDidLoad() {
        super.viewDidLoad()
        
    }
    @IBAction func connect(_ sender: Any) {
        if socket.connectToServer(){
             print("成功连接到服务器")
        }
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
      
      let userInfo =  UserInfo.Builder()
        userInfo.name = "张珊"
        userInfo.level = 3
        
       let textMsg =  TextMessage.Builder()
        textMsg.user = try! userInfo.build()
        textMsg.text = "你好吗,服务器"
        
        let gift = GiftMessage.Builder()
        gift.user = try! userInfo.build()
        gift.giftUrl = "www.baidu.com"
        gift.giftname = "小黄瓜"
        gift.giftCount = "4"
        
        let data =  (try! gift.build()).data()
        print(data.count)
        socket.sendData(data, 2)
    }
}

